<!-- src/components/Task/TaskHeader.vue -->
<template>
  <header class="header">
    <div class="header-left">
      <el-button class="menu-btn" @click="$emit('toggle-sidebar')">
        <template #icon>
          <component :is="sidebarCollapsed ? Expand : Fold" />
        </template>
      </el-button>

      <div class="calendar-title">
        <el-icon class="calendar-icon"><Calendar /></el-icon>
        <span class="title-text">日历</span>
      </div>

      <div class="current-date">
        <div class="date-main">2025年10月</div>
        <div class="date-lunar">农历八月 ~ 九月</div>
      </div>
    </div>

    <div class="header-right">
      <el-button class="icon-btn" @click="showSearch">
        <template #icon><Search /></template>
      </el-button>
      <el-button class="icon-btn" @click="showHelp">
        <template #icon><QuestionFilled /></template>
      </el-button>

      <div class="capsule-button">
        <button class="capsule-item capsule-left" @click="$emit('go-calendar')">
          <el-icon><Calendar /></el-icon>
        </button>
        <button class="capsule-item capsule capsule-right active" @click="$emit('go-task')">
          <el-icon><Check /></el-icon>
        </button>
      </div>

      <el-button class="icon-btn" @click="toggleGrid">
        <template #icon><Grid /></template>
      </el-button>
      <div class="user-avatar" @click="showUserMenu">
        <img src="@/assets/img1.jpg" alt="用户头像" />
      </div>
    </div>
  </header>
</template>

<script lang="ts" setup>
import { Calendar, Search, QuestionFilled, Check, Grid, Expand, Fold } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

defineProps<{
  sidebarCollapsed: boolean
}>()

const emit = defineEmits<{
  (e: 'toggle-sidebar'): void
  (e: 'go-calendar'): void
  (e: 'go-task'): void
  (e: 'show-user-menu'): void
}>()

const showSearch = () => ElMessage.info('搜索功能')
const showHelp = () => ElMessage.info('帮助信息')
const toggleGrid = () => ElMessage.info('切换网格视图')
const showUserMenu = () => emit('show-user-menu')
</script>

<style scoped>
/* 复用原样式 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: #ffffff;
  border-bottom: 1px solid #e0e0e0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.menu-btn {
  border: none;
  background: none;
  font-size: 18px;
  color: #666;
}

.calendar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.calendar-icon {
  font-size: 20px;
  color: #1976d2;
}

.current-date {
  margin-left: 16px;
}

.date-main {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.date-lunar {
  font-size: 12px;
  color: #666;
}

.icon-btn {
  border: none;
  background: none;
  color: #666;
  font-size: 16px;
}

.capsule-button {
  display: inline-flex;
  border-radius: 20px;
  border: 1px solid #ddd;
  background: white;
  overflow: hidden;
}

.capsule-item {
  border: none;
  background: none;
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  outline: none;
  position: relative;
}

.capsule-item:first-child::after {
  content: '';
  position: absolute;
  right: 0;
  top: 25%;
  height: 50%;
  width: 1px;
  background: #ddd;
}

.capsule-item:hover {
  background: #f5f5f5;
}

.capsule-item.active {
  background: #1976d2;
}

.capsule-item.active .el-icon {
  color: white;
}

.capsule-item .el-icon {
  font-size: 16px;
  color: #666;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>